/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newcrunch.codeanalysis;

import java.awt.Color;
import javax.swing.JProgressBar;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

/**
 *
 * @author WL
 */
public class ProgressDisplay extends javax.swing.JDialog {
    private boolean fbDone; 
    private boolean checkstyleDone;
    private boolean pmdDone;
    
    /**
     * Creates new form ProgressDisplay
     */
    public ProgressDisplay(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        fbStatus.setBackground(rootPanel.getBackground());
        pmdStatus.setBackground(rootPanel.getBackground());
        checkstyleStatus.setBackground(rootPanel.getBackground());
        fbProgress.setString("Running...");
        checkstyleProgress.setString("Running...");
        PMDProgress.setString("Running...");
    }
    
    public JProgressBar getCheckstyleProgressBar()
    {
        return checkstyleProgress;
    }
    
    public JTextField getCheckstyleStatusDisp()
    {
        return checkstyleStatus;
    }
    
    public JProgressBar getFindbugsProgressBar()
    {
        return fbProgress;
    }
    
    public JTextField getFindbugsStatusDisp()
    {
        return fbStatus;
    }
    
    public JProgressBar getPMDProgressBar()
    {
        return PMDProgress;
    }
    
    public JTextField getPMDStatusDisp()
    {
        return pmdStatus;
    }
    
    public void setCheckstyleDone()
    {
        SwingUtilities.invokeLater(new Runnable(){
           @Override
           public void run()
           {        
                checkstyleDone = true;
                checkstyleProgress.setValue(checkstyleProgress.getMaximum());
                checkstyleProgress.setString("Done");
                checkstyleStatus.setText("Completed");
                checkAllDone();
           }
        });        
    }
    
    public void setFindbugsDone()
    {
        SwingUtilities.invokeLater(new Runnable(){
           @Override
           public void run()
           {        
                fbDone = true;
                fbProgress.setValue(fbProgress.getMaximum());
                fbProgress.setString("Done");
                fbStatus.setText("Completed");
                checkAllDone();
           }
        });
    }
    
    public void setPMDDone()
    {
        SwingUtilities.invokeLater(new Runnable(){
           @Override
           public void run()
           {
                pmdDone = true;
                PMDProgress.setValue(PMDProgress.getMaximum());
                PMDProgress.setString("Done");
                pmdStatus.setText("Completed");
                checkAllDone();               
           }
        });
    }
    
    private void checkAllDone()
    {
        if (allDone())
        {
            setVisible(false);
            this.dispose();
        }   
    }
    
    public boolean allDone()
    {
        return fbDone && checkstyleDone && pmdDone;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rootPanel = new javax.swing.JPanel();
        fbPanel = new javax.swing.JPanel();
        fbLabel = new javax.swing.JLabel();
        fbProgress = new javax.swing.JProgressBar();
        fbStatus = new javax.swing.JTextField();
        checkstylePanel = new javax.swing.JPanel();
        checkstyleLabel = new javax.swing.JLabel();
        checkstyleProgress = new javax.swing.JProgressBar();
        checkstyleStatus = new javax.swing.JTextField();
        pmdPanel = new javax.swing.JPanel();
        pmdLabel = new javax.swing.JLabel();
        PMDProgress = new javax.swing.JProgressBar();
        pmdStatus = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Code Analysis Display");

        fbPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        fbLabel.setText("FindBugs");

        fbProgress.setStringPainted(true);

        fbStatus.setBackground(new java.awt.Color(240, 240, 240));
        fbStatus.setEditable(false);
        fbStatus.setBorder(null);
        fbStatus.setRequestFocusEnabled(false);

        javax.swing.GroupLayout fbPanelLayout = new javax.swing.GroupLayout(fbPanel);
        fbPanel.setLayout(fbPanelLayout);
        fbPanelLayout.setHorizontalGroup(
            fbPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fbPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(fbPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fbProgress, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
                    .addGroup(fbPanelLayout.createSequentialGroup()
                        .addComponent(fbLabel)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(fbStatus))
                .addContainerGap())
        );
        fbPanelLayout.setVerticalGroup(
            fbPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(fbPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(fbLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(fbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(fbProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        checkstylePanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        checkstyleLabel.setText("Checkstyle");

        checkstyleProgress.setStringPainted(true);

        checkstyleStatus.setBackground(new java.awt.Color(240, 240, 240));
        checkstyleStatus.setEditable(false);
        checkstyleStatus.setBorder(null);
        checkstyleStatus.setRequestFocusEnabled(false);

        javax.swing.GroupLayout checkstylePanelLayout = new javax.swing.GroupLayout(checkstylePanel);
        checkstylePanel.setLayout(checkstylePanelLayout);
        checkstylePanelLayout.setHorizontalGroup(
            checkstylePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(checkstylePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(checkstylePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(checkstylePanelLayout.createSequentialGroup()
                        .addComponent(checkstyleLabel)
                        .addGap(0, 304, Short.MAX_VALUE))
                    .addComponent(checkstyleProgress, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
                    .addComponent(checkstyleStatus))
                .addContainerGap())
        );
        checkstylePanelLayout.setVerticalGroup(
            checkstylePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(checkstylePanelLayout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(checkstyleLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(checkstyleStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(checkstyleProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pmdPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        pmdLabel.setText("PMD");

        PMDProgress.setStringPainted(true);

        pmdStatus.setBackground(new java.awt.Color(240, 240, 240));
        pmdStatus.setEditable(false);
        pmdStatus.setBorder(null);
        pmdStatus.setRequestFocusEnabled(false);

        javax.swing.GroupLayout pmdPanelLayout = new javax.swing.GroupLayout(pmdPanel);
        pmdPanel.setLayout(pmdPanelLayout);
        pmdPanelLayout.setHorizontalGroup(
            pmdPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pmdPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pmdPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(PMDProgress, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
                    .addGroup(pmdPanelLayout.createSequentialGroup()
                        .addComponent(pmdLabel)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(pmdStatus))
                .addContainerGap())
        );
        pmdPanelLayout.setVerticalGroup(
            pmdPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pmdPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pmdLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(pmdStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PMDProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout rootPanelLayout = new javax.swing.GroupLayout(rootPanel);
        rootPanel.setLayout(rootPanelLayout);
        rootPanelLayout.setHorizontalGroup(
            rootPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rootPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(rootPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fbPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(checkstylePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pmdPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        rootPanelLayout.setVerticalGroup(
            rootPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rootPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(checkstylePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pmdPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(fbPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(rootPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(rootPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JProgressBar PMDProgress;
    private javax.swing.JLabel checkstyleLabel;
    private javax.swing.JPanel checkstylePanel;
    private javax.swing.JProgressBar checkstyleProgress;
    private javax.swing.JTextField checkstyleStatus;
    private javax.swing.JLabel fbLabel;
    private javax.swing.JPanel fbPanel;
    private javax.swing.JProgressBar fbProgress;
    private javax.swing.JTextField fbStatus;
    private javax.swing.JLabel pmdLabel;
    private javax.swing.JPanel pmdPanel;
    private javax.swing.JTextField pmdStatus;
    private javax.swing.JPanel rootPanel;
    // End of variables declaration//GEN-END:variables
}
